﻿@model IEnumerable<Citi.Scheduler.WebUi.Models.MachineCurrentExecutionTextModel>
@{
    ViewBag.Title = "Current Execution - Text";
}
<h2>
    Current Execution - Text</h2>
<table class="table table-bordered table-striped">
    <tr>
        <th style="width: 300px">
            Hostname/Services and Actions
        </th>
        <th>
            Date
        </th>
        <th>
            Description
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                <strong>@Html.DisplayFor(modelItem => item.Hostname)</strong>
            </td>
            <td rowspan="2">
                @Html.DisplayFor(modelItem => item.Date)
            </td>
            <td rowspan="2" @(item.Date.AddMinutes(10) < DateTime.Now ? "style=color:red" : string.Empty)>
                @if (item.Description.StartsWith("Executing"))
                {
                    var routineExecutionId = item.Description.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Last();
                    
                    @Html.Raw(item.Description.Replace(routineExecutionId, string.Format(@"<a target=""_blank"" href=""{0}"">{1}</a>", Url.Action("Index",
                        "RoutineExecutionHistory", new { routineExecutionId = routineExecutionId }), routineExecutionId)));
                }
                else
                {
                    @item.Description
                }
                <a href="@string.Format("/machine/FullExecutionLog?machineName={0}", item.MachineFullName)" class="icon-search">
                </a>
            </td>
        </tr>
        <tr>
            <td>
                @if (item.Services != null)
                {
                    foreach (var service in item.Services)
                    {
                        var guid = Guid.NewGuid();
                    
                    <div style="height: 18px;">
                        &nbsp;&nbsp;&nbsp;&nbsp;@Html.DisplayFor(serviceItem => service.ServiceName) (@service.StatusText)
                        @if (service.Running)
                        {
                            <a href="@string.Format("/machine/StopService?serviceName={0}&machineName={1}", service.ServiceName, service.MachineName)"
                                onclick="if (!confirm('Are you share?')) return false;" class="floatRight">
                                <img src="@Url.Content("~/Content/Images/stop.png")" alt="Stop" style="width:16px"/>
                            </a>
                            <a href="@string.Format("/machine/RestartService?serviceName={0}&machineName={1}", service.ServiceName, service.MachineName)"
                                onclick="if (!confirm('Are you share?')) return false;" class="floatRight">
                                <img src="@Url.Content("~/Content/Images/restart.png")" alt="Restart" style="width:16px" />
                            </a>
                            <img src="@Url.Content("~/Content/Images/play.png")" alt="Start" style="width:16px; margin-top:2px;" class="floatRight disabled"/>               
                        }
                        else
                        {
                            <img src="@Url.Content("~/Content/Images/stop.png")" alt="Stop" style="width:16px; " class="floatRight disabled"/>
                            <img src="@Url.Content("~/Content/Images/restart.png")" alt="Restart" style="width:16px; " class="floatRight disabled"/>
                            <a href="@string.Format("/machine/StartService?serviceName={0}&machineName={1}", service.ServiceName, service.MachineName)" class="floatRight">
                                <img src="@Url.Content("~/Content/Images/play.png")" alt="Start" style="width:16px; margin-top:2px;" />
                            </a>
                        }
                    </div>
                    }
                }
            </td>
        </tr>
    }
</table>
